package ac.github.os.internal.core.selector.impl

import ac.github.os.api.common.SingleList
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.holder.damage.DamageHolder
import ac.github.os.internal.core.objective.Objective
import ac.github.os.internal.core.selector.Selector
import ac.github.os.internal.session.Session
import ac.github.os.util.adaptObjective
import taboolib.common.platform.Awake

abstract class DamageSelector : Selector {
    override fun doSelect(session: Session, config: StringConfig): SingleList<Objective> {
        return SingleList<Objective>().apply {

            val holder = session.holder
            if (holder is DamageHolder) {
                add(this@DamageSelector.run(holder, config))
            }
        }
    }

    abstract fun run(damageHolder: DamageHolder, config: StringConfig): Objective

}

@Awake
class AttackerSelector : DamageSelector() {
    override val namespace: String
        get() = "attacker"

    override fun run(damageHolder: DamageHolder, config: StringConfig): Objective {
        return damageHolder.damager.adaptObjective()
    }
}

@Awake
class DefenderSelector : DamageSelector() {
    override val namespace: String
        get() = "defender"

    override fun run(damageHolder: DamageHolder, config: StringConfig): Objective {
        return damageHolder.entity.adaptObjective()
    }
}
//
//@Awake
//class ProjectileSelector : DamageSelector() {
//    override fun run(damageHolder: DamageHolder, config: StringConfig): Objective {
//        return if (damageHolder.isProjectile) damageHolder.projectile.
//    }
//
//    override val namespace: String
//        get() = "projectile"
//
//}
